rm(list=ls())

library(foreign)
library(ggplot2)
library(gridExtra)
library(grid)
library(lattice)

################# WITH THE CURRENT STUDY (KNOWLEDGE)

setwd("")

diffdiffall<-read.csv("study_comparison_knowledge_with_this_study_with_meta.csv")
attach(diffdiffall) 

color.names<-c("grey55", "black")
xaxislabels <- c("Meta Analysis \n [Random Effects]", "Meta Analysis \n [Weighted by Inverse-Variance]","Meta Analysis \n [Weighted by N]","This Study \n[USA]", 
                 "Bruce and Lima (2019) \n [Brazil]",
                 "De Leon and Rizzi (2014) \n [Brazil]",
                 "Holbein and Rangel (2020) \n [Brazil]","Braconnier et al. (2017) \n [France]","Loewen et al. (2008) \n [Canada]", 
                 "Shineman (2018) \n [USA]")

plot1<-ggplot(diffdiffall, aes(y=late,  x=reorder(variable_label, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=factor(color), size=n, shape=factor(color))) +
  geom_errorbar(aes(ymin=late-1.96*se, ymax=late+1.96*se, colour=factor(color)), width=0, size=2) +
  geom_errorbar(aes(ymin=late-1.64*se, ymax=late+1.64*se, colour=factor(color)), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect on Political Knowledge (Proportion Correct)", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=30)) +
  scale_size(range = c(7, 15)) +
  scale_y_continuous(limits=c(-.25, .25)) + 
  coord_flip() + scale_colour_manual(values=color.names) + theme(legend.position="none") +
  annotate("text", x = 10.3, y=0.07671161, label = "b=0.077, p=0.04, se=0.04", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 9.3, y=0.03, label = "b=0.03, p=0.47, se=0.04", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 8.3, y=0.0232568, label = "b=0.02, p=0.13, se=0.02", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 7.3, y=-0.01423, label = "b=-0.01, p=0.256, se=0.01", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 6.3, y=0.01646, label = "b=0.02, p=0.67, se=0.04", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 5.3, y=0.148, label = "b=0.148, p=0.01, se=0.03", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 4.3, y=-0.04, label = "b=-0.04, p=0.18, se=0.03", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 3.4, y=-0.012, label = "b=-0.01, p=0.21, se=0.01", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 2.4, y=0.022, label = "b=0.02, p=0.03, se=0.01", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 1.4, y=0.033, label = "b=0.03, p=0.18, se=0.02", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  scale_x_discrete(labels = xaxislabels) +
  theme(axis.text.y = element_text(color = c("black", "black", "black", "blue", "grey55", "grey55", "grey55", "grey55", "grey55", "grey55", "grey55"))) +
  annotate("text", x = 0.6, y=0.15, label = "Increases Knowledge", size=9, fontface="bold", colour="grey55", alpha=0.6, angle=0) +
  annotate("text", x = 0.6, y=-0.15, label = "Decreases Knowledge", size=9, fontface="bold", colour="grey55", alpha=0.6, angle=0) 

plot1
ggsave(plot1, file="study_comparison_with_this_study_knowledge.png", width=10, height=6.5, scale=2)


################# WITH THE CURRENT STUDY (INTEREST)

setwd("")

diffdiffall<-read.csv("study_comparison_interest_with_meta.csv")
attach(diffdiffall) 

color.names<-c("grey55", "black")
xaxislabels <- c("Meta Analysis \n [Random Effects]", "Meta Analysis \n [Weighted by Inverse-Variance]","Meta Analysis \n [Weighted by N]","This Study \n[USA]", "Holbein and Rangel (2020) \n [Brazil]",
                 "Braconnier et al. (2017) \n [France]", "Shineman (2018) \n [USA]", "Gaebler et al. (2019) \n [Austria]", "Shineman (2012) \n [Austria]")

plot1<-ggplot(diffdiffall, aes(y=late,  x=reorder(variable_label, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=factor(color), size=n, shape=factor(color))) +
  geom_errorbar(aes(ymin=late-1.96*se, ymax=late+1.96*se, colour=factor(color)), width=0, size=2) +
  geom_errorbar(aes(ymin=late-1.64*se, ymax=late+1.64*se, colour=factor(color)), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect on Political Interest (1-4)", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=30)) +
  scale_size(range = c(7, 15)) +
  scale_y_continuous(limits=c(-1.15, 1.15)) + 
  coord_flip() + scale_colour_manual(values=color.names) + theme(legend.position="none") +
  annotate("text", x = 9.3, y=0.53, label = "b=0.53, p=0.09, se=0.31", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 8.3, y=-0.08, label = "b=-0.08, p=0.57, se=0.14", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
   annotate("text", x = 7.3, y=-0.1925762, label = "b=-0.19, p=0.19, se=0.14", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
   annotate("text", x = 6.3, y=0.0680595, label = "b=0.07, p=0.17, se=0.05", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 5.3, y=0.04029, label = "b=0.04, p=0.11, se=0.03", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 4.3, y=-0.01708, label = "b=-0.02, p=0.854, se=0.09", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 3.4, y=0.031, label = "b=0.03, p=0.21, se=0.02", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 2.4, y=0.04, label = "b=0.04, p=0.08, se=0.02", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  annotate("text", x = 1.4, y=0.03, label = "b=0.03, p=0.36, se=0.03", size=7, fontface="bold", colour="blue", alpha=0.8, angle=0) +
  
  scale_x_discrete(labels = xaxislabels) +
  theme(axis.text.y = element_text(color = c("black", "black", "black", "blue", "grey55", "grey55", "grey55", "grey55", "grey55", "grey55"))) +
  annotate("text", x = 0.6, y=0.575, label = "Increases Interest", size=9, fontface="bold", colour="grey55", alpha=0.6, angle=0) +
  annotate("text", x = 0.6, y=-0.575, label = "Decreases Interest", size=9, fontface="bold", colour="grey55", alpha=0.6, angle=0) 

plot1
ggsave(plot1, file="study_comparison_with_this_study_interest.png", width=10, height=6, scale=2)

 










